function assignCustomBallIDs()
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM  ASSIGNMENTS BELOW HERE
--------------------------------------------------------------------------------------------------------------




--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS ABOVE HERE
--------------------------------------------------------------------------------------------------------------
end

--------------------------------------------------------------------------------------------------------------

function BallUpdate(idx)
	local as = gSportsRNA
	local state = as:GetTable("wvState")
	local ball = as:GetTable("wvBall", idx)
	
	local wipe3d = as:GetTable("wvWipe", idx)
	local stadium = as:GetTable("wvStadium", idx)
	
	db.wipe3d[idx].leagueID = as:GetInt(wipe3d, "leagueID")
	
	db.wipe3d[idx].leagueID = getTournamentGraphics(db.wipe3d[idx].leagueID)
	
	db.stadium[idx].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )

	db.ball[idx].model = as:GetInt(ball, "ballModel") 
	db.ball[idx].lightType = as:GetInt(state, "wvAttribStadLighting")
	db.ball[idx].stadiumID = as:GetInt(state, "wvAttribStadID")
	
	weather = as:GetInt(state, "wvAttribStadWeather" )
	
	assignCustomBallIDs()
	db.ball[idx].model = getBallID(db.stadium[idx].homeKitTeamID,db.ball[idx].model,db.wipe3d[idx].leagueID,idx,weather)

end

function BallAssetBind(ball)
	local gr = gRenderables
   	local lod = 0

	gr:AddCallback(ball, lod, "BallUpdate(?)")
	gr:AddAsset(ball, lod, "shader", "data/fifarna/shader.big")
	gr:AddAsset(ball, lod, "ballmesh", "data/sceneassets/ball/ball_${db.ball[?].model}.rx3")
	gr:AddAsset(ball, lod, "balltex", "data/sceneassets/ball/ball_${db.ball[?].model}_textures.rx3")
	gr:AddAsset(ball, lod, "charcmn", "data/sceneassets/charactercmn/charactercmn_${db.ball[?].lightType}.rx3")	
	gr:AddAsset(ball, lod, "coverage", "data/sceneassets/pitch/pitchcovmap_${db.ball[?].stadiumID}_${db.ball[?].lightType}_textures.rx3")	
	gr:CreateMaterialFromAttribulator(ball, lod, "ballmesh", "ball", "${AttribMaterial('ball')}" )
	gr:SetTexture(ball, lod, "ballmesh", "textures", "diffuseTexture", "balltex", "ball_cm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "normalMap", "balltex", "ball_nm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "coverageMap", "coverage", "pitch")
--	gr:SetTextureFromRuntime(ball, lod, "ballmesh", "textures", "shadowMap", "ShadowMapTexture")	-- bind from game runtime!
	return ball
end

teamBalls = {}
tournamentBalls = {}

function getBallID(team,ad,tourn,idx,weatherID)

if (globalBallEnabled) then
return globalBallID
elseif ((idx == 0) and (arenaModeBall ~= -1)) then
return arenaModeBall
elseif ((weatherID == 2) and (tournamentBalls[tourn] ~= nil)) then
return tournamentBallsSnow[tourn]
elseif (tournamentBalls[tourn] ~= nil) then
return tournamentBalls[tourn]
elseif ((weatherID == 2) and (teamBalls[team] ~= nil)) then
return teamBallsSnow[team]
elseif (teamBalls[team] ~= nil) then
return teamBalls[team]
else
return ad
end

end

function assignTeamBall(team,ad)
teamBalls[team] = ad
end

function assignTournamentBall(tourn,ad)
tournamentBalls[tourn] = ad
end

globalBallEnabled = false
globalBallID = 1

function useGlobalBall(id)
globalBallEnabled = true
globalBallID = id
end

globalBallEnabled = false
globalBallID = 1


arenaModeBall = -1

function setArenaModeBall(id)
arenaModeBall = id
end

teamBallsSnow = {}
tournamentBallsSnow = {}

function assignTeamBallSnow(team,ad)
teamBallsSnow[team] = ad
end

function assignTournamentBallSnow(tourn,ad)
tournamentBallsSnow[tourn] = ad
end

frTourn = -1

function useTournamentGraphicsInFriendly(id)
frTourn = id
end

function getTournamentGraphics(id)
if (id == -1) then
return frTourn
end

return id
end

--Revolution Mod V1.2
--Edited by scouser09
